package cn.itcast.controller;

import cn.itcast.domain.Accounts;
import cn.itcast.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.Errors;
import org.springframework.validation.FieldError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/account")
public class AccountController {

        @Autowired
        private AccountService accountService;

        @GetMapping
        public Object findAll()throws Exception{
            List<Accounts> all = accountService.findAll();
            return all;
        }
        @GetMapping("/{pageNum}/{pageSize}")
        public Object findPageAll( @PathVariable Integer pageNum, @PathVariable Integer pageSize)throws Exception{

            return   accountService.pageQure(pageNum,pageSize);
        }
        @GetMapping("/{id}")
        public Object findById(@PathVariable Integer id)throws Exception{
            return accountService.findById(id);
        }

        @PostMapping
        public Object add(  @RequestBody Accounts accounts)throws Exception{
            accountService.add(accounts);
            return true;
        }

        @DeleteMapping("/{id}")
        public Object delete( @PathVariable Integer id)throws Exception{

        accountService.delete(id);
        return true;

        }
    @PutMapping
    public Object update(  @RequestBody Accounts accounts)throws Exception{

            accountService.update(accounts);
            return true;
    }
}
